<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hypref_mall
 * contact  hyperf_mall@163.com
 */
namespace App\Repository;

use App\Model\MemberPointModel;
use Hyperf\Di\Annotation\Inject;

class MemberPointRepository extends BaseRepository
{
    /**
     * @Inject
     * @var MemberPointModel
     */
    protected $model;


    /**
     * Notes: 添加/初始化添加会员积分表
     * Author: Bruce.z
     * DateTime: 2022/7/19 11:20
     * @param $member_id
     * @param $point
     */
    public function initAdd($member_id, $point):void
    {
        $row = $this->getOne(['member_id'=>$member_id],['point','use_point','id']);
        if(empty($row)){
            $this->baseAdd([
                'member_id'=>$member_id,
                'point'=>$point,
                'use_point'=>$point,
            ]);
        }else{
            $this->updateByConditions(['id'=>$row['id']], [
                'point'=>$row['point'] + $point,
                'use_point'=>$row['use_point'] + $point,
            ]);
        }
    }
}
